package cn.hairui.blog.dao;

import cn.hairui.blog.entity.Messagereply;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 留言回复表 Mapper 接口
 * </p>
 *
 * @author laoganbu
 * @since 2020-04-20
 */
@Mapper
public interface MessagereplyMapper extends BaseMapper<Messagereply> {

    @Select("SELECT\n" +
            "    t1.id          AS id,\n" +
            "    t1.content     AS content,\n" +
            "    t1.msgid       AS msgid,\n" +
            "    t1.fromaccount AS fromaccount,\n" +
            "    (\n" +
            "        SELECT\n" +
            "            t2.nickname\n" +
            "        FROM\n" +
            "            USER t2\n" +
            "        WHERE\n" +
            "            t1.fromaccount=t2.account limit 1) AS fromusername,\n" +
            "    (\n" +
            "        SELECT\n" +
            "            t4.prophoto\n" +
            "        FROM\n" +
            "            USER t4\n" +
            "        WHERE\n" +
            "            t1.fromaccount=t4.account) AS prophoto,\n" +
            "    t1.toaccount                       AS toaccount,\n" +
            "    (\n" +
            "        SELECT\n" +
            "            t3.nickname\n" +
            "        FROM\n" +
            "            USER t3\n" +
            "        WHERE\n" +
            "            t1.toaccount=t3.account limit 1) AS tousername,\n" +
            "    t1.replytime                             AS replytime\n" +
            "FROM\n" +
            "    messagereply t1\n" +
            "WHERE\n" +
            "    t1.msgid=#{msgId}\n" +
            "ORDER BY\n" +
            "    t1.id ASC,\n" +
            "    t1.replytime ASC")
    List<Map> selectByMsgId(int msgId);
}
